const express = require("express");
const router = express.Router();

const {
  createOrder,
  getAllOrders,
  getOrderById,
  updateOrder,
  deleteOrder,
} = require("../controllers/posController");

const { authMiddleware, hasPermission } = require("../middleware/authMiddleware");

// CREATE a new POS order
router.post(
  "/",
  authMiddleware,
  hasPermission("POSOrders", "Add"),
  createOrder
);

// GET all POS orders
router.get(
  "/",
  authMiddleware,
  hasPermission("POSOrders", "View"),
  getAllOrders
);

// GET a single POS order by ID
router.get(
  "/:id",
  authMiddleware,
  hasPermission("POSOrders", "View"),
  getOrderById
);

// UPDATE a POS order
router.put(
  "/:id",
  authMiddleware,
  hasPermission("POSOrders", "Edit"),
  updateOrder
);

// DELETE a POS order
router.delete(
  "/:id",
  authMiddleware,
  hasPermission("POSOrders", "Delete"),
  deleteOrder
);

module.exports = router;
